hive select 限制 字段长度 hive select as |
您所在的位置:网站首页 › hive string 长度 › hive select 限制 字段长度 hive select as |
例子:班级表classes.txt,学生表students.txt,两个表文件数据如下: classes: 1,班级1 2,班级2 3,班级3student: 11,1,张三 12,1,李四 13,1,王五 21,2,Tom 22,2,Gerry 23,2,Simon 24,2,Jim 91,\N,Jeffrey 92,\N,Leo 93,\N,even 94,\N,aaron 95,\N,addison查询实例: 一、from语法: 1.正常from: select * from students; 2.from语句提前 from students select *; 二、cte语法: 1. 获取班级号为1的学生信息: with tmp as (select studentid as sid,classid as cid,studentname as name from students where classid=1) from tmp select *; 2. 获取总学生数、已经分配班级的学生数、未分配班级的学生数(作业1)。 分析: 总学生数:studentid的总数 分配班级的学生数:classid不为空的学生总数 未分配的学生数: classid为空的学生数 结果: 12 7 5 三、where & group by语法实例: 1. 获取学生数大于3的班级id from students select classid where classid is not null group by classid having count(studentid) > 3; 四、order by、sort by排序语法: 1. 使用order by根据学生id倒序。 select * from students order by studentid desc; 2. 设置hive.mapred.mode为strict,然后在进行order by操作。 set hive.mapred.mode=strict; select * from students order by studentid desc; 会出现异常 select * from students order by studentid desc limit 5; 3. 使用sort by根据学生id排序。 select * from students sort by studentid desc; 4. 设置mapreduce.job.reduces个数为两个,然后再使用sort by进行排序。(说明sort by是根据reduce个数进行局部排序的) set mapreduce.job.reduces=2; select * from students sort by studentid desc;
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |